//
//  UIViewController+Tracking.m
//  dynamic
//
//  Created by young on 16/6/30.
//  Copyright © 2016年 young. All rights reserved.
//

#import "UIViewController+OAExtension.h"

#import <objc/runtime.h>

@interface UIViewController ()

@end



@implementation UIViewController (OAExtension)


+ (void)load
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];
        Method originalMethod = class_getInstanceMethod(class, @selector(viewWillDisappear:));
        Method swapMethod = class_getInstanceMethod(class, @selector(oa_viewWillDisappear:));
        method_exchangeImplementations(swapMethod, originalMethod);
    });
}


- (void)popToController:(Class)aClass
{
    for (UIViewController *vc in self.navigationController.viewControllers)
    {
        if ([vc isKindOfClass:aClass])
        {
            [self.navigationController popToViewController:vc animated:YES];
            return;
        }
    }
}

#pragma mark - Method Swizzling

- (void)oa_viewWillDisappear:(BOOL)animated {
    [self oa_viewWillDisappear:animated];
    
    [self.view endEditing:YES];
}

@end
